package com.caseprocessing.model;

import java.util.List;

/**
 * 布局元素模型
 * 表示页面中的结构化布局元素（如头部、签名区域、印章区域等）
 */
public class LayoutElement {
    
    private String type;  // header, signature_area, seal_area, table, footer等
    private BoundingBox bbox;
    private List<String> content;
    private boolean hasSignature;
    private String signatureType;  // handwritten, electronic, stamped
    private boolean hasSeal;
    private String sealType;  // official, personal, electronic
    
    public LayoutElement() {}
    
    public LayoutElement(String type, BoundingBox bbox) {
        this.type = type;
        this.bbox = bbox;
    }
    
    // Getters and Setters
    public String getType() { return type; }
    public void setType(String type) { this.type = type; }
    
    public BoundingBox getBbox() { return bbox; }
    public void setBbox(BoundingBox bbox) { this.bbox = bbox; }
    
    public List<String> getContent() { return content; }
    public void setContent(List<String> content) { this.content = content; }
    
    public boolean hasSignature() { return hasSignature; }
    public void setHasSignature(boolean hasSignature) { this.hasSignature = hasSignature; }
    
    public String getSignatureType() { return signatureType; }
    public void setSignatureType(String signatureType) { this.signatureType = signatureType; }
    
    public boolean hasSeal() { return hasSeal; }
    public void setHasSeal(boolean hasSeal) { this.hasSeal = hasSeal; }
    
    public String getSealType() { return sealType; }
    public void setSealType(String sealType) { this.sealType = sealType; }
    
    /**
     * 判断是否为页眉元素
     */
    public boolean isHeader() {
        return "header".equals(type);
    }
    
    /**
     * 判断是否为签名区域
     */
    public boolean isSignatureArea() {
        return "signature_area".equals(type);
    }
    
    /**
     * 判断是否为印章区域
     */
    public boolean isSealArea() {
        return "seal_area".equals(type);
    }
    
    /**
     * 判断是否为表格元素
     */
    public boolean isTable() {
        return "table".equals(type);
    }
    
    /**
     * 获取内容文本
     */
    public String getContentText() {
        if (content == null || content.isEmpty()) {
            return "";
        }
        return String.join(" ", content);
    }
    
    /**
     * 验证签名区域的有效性
     */
    public boolean isValidSignatureArea() {
        return isSignatureArea() && hasSignature && signatureType != null;
    }
    
    /**
     * 验证印章区域的有效性
     */
    public boolean isValidSealArea() {
        return isSealArea() && hasSeal && sealType != null;
    }
}